//
//  CZComment.swift
//  GZWeibo666
//
//  Created by Yuan on 15/12/2.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

class CZComment: NSObject {
    //评论时间
    var created_at : String?
    //评论id
    var id : Int = 0
    //评论内容
    var text : String?
    //评论来源
    var source : String?
    //评论用户
    var user : CZUser?
    /// 行高
    var rowHeight: CGFloat?
    /// 是否是微博认证用户，即加V用户，true：是，false：否
    var verified: Bool = false
    
    /// verified_type 没有认证:-1   认证用户:0  企业认证:2,3,5  达人:220
    var verified_type: Int = -1 {
        didSet {
            // 没有认证:-1   认证用户:0  企业认证:2,3,5  达人:220
            switch verified_type {
            case 0:
                verifiedImage = UIImage(named: "avatar_vip")
            case 2,3,5:
                verifiedImage = UIImage(named: "avatar_enterprise_vip")
            case 220:
                verifiedImage = UIImage(named: "avatar_grassroot")
            default:
                verifiedImage = nil
            }
        }
    }
    
    /// 认证类型对应的图片
    var verifiedImage: UIImage?
    
    /// 会员等级 1-6
    var mbrank: Int = 0 {
        didSet {
            if mbrank > 0 && mbrank < 7 {
                // 能到这里面来,是会员
                mbrankImage = UIImage(named: "common_icon_membership_level\(mbrank)")
            } else {
                // 不是会员,清空图标
                mbrankImage = nil
            }
        }
    }
    
    /// 会员等级对应的图片
    var mbrankImage: UIImage?
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            if let dict = value as? [String: AnyObject] {
                // 在这里字典转模型, 赋值给user属性
                user = CZUser(dict: dict)
            }
            return
        }
        // 调用父类的方法
        super.setValue(value, forKey: key)
    }

    /// 字典转模型
    init(dict: [String: AnyObject]) {
        super.init()
        
        // 字典转模型
        setValuesForKeysWithDictionary(dict)
    }
    
    /// 字典的key在模型中找不到对应的属性
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
}
